package controllers

import (
	"github.com/astaxie/beego"
	"forhouyu/models"
	"forhouyu/utils"
)

type AppController struct {
	beego.Controller
}


func (this *AppController) Cert_qysb() {
	this.Layout = "index.html"
	this.TplName = "cert_qysb.html"
}

func (this *AppController) Cert_wxd() {

	this.Layout = "index.html"
	this.TplName = "cert_wxd.html"
}

func (this *AppController) Cert_cpdj() {

	this.Layout = "index.html"
	this.TplName = "cert_cpdj.html"
}

func (this *AppController) Cert_cpxx_submit() {

	this.Layout = "index.html"
	this.TplName = "cert_cpxx_submit.html"
}

func (this *AppController) Add_cert_cpdj() {
	cert_cpdj := models.Cert_cpdj{}
	err := this.ParseForm(&cert_cpdj)
	utils.CheckErr(err)

	beego.Info(cert_cpdj)

	models.AddCert_cpdj(cert_cpdj)

	this.Layout = "index.html"
	this.TplName = "cert_cpdj.html"
}

func (this *AppController) Add_cert_qysb() {
	cert_qysb := models.Cert_qysb{}
	err := this.ParseForm(&cert_qysb)
	utils.CheckErr(err)

	beego.Info(cert_qysb)

	models.AddCert_qysb(cert_qysb)

	this.Layout = "index.html"
	this.TplName = "cert_qysb.html"
}

func (this *AppController) Add_cert_wxd() {
	cert_wxd := models.Cert_wxd{}
	err := this.ParseForm(&cert_wxd)
	utils.CheckErr(err)

	models.AddCert_wxd(cert_wxd)

	this.Layout = "index.html"
	this.TplName = "cert_wxd.html"
}

func (this *AppController) Add_cert_cpxx_submit() {
	cert_cpxx := models.Cert_cpxx{}
	err := this.ParseForm(&cert_cpxx)
	utils.CheckErr(err)

	models.AddCert_cpxx(cert_cpxx)

	this.Layout = "index.html"
	this.TplName = "cert_cpxx_submit.html"
}


func (this *AppController)  Query_cert_qysb(){
	cert_qysbs  := []models.Cert_qysb{}
	cert_qysbs = models.ListCert_qysbs()

	this.Data["datas"] = cert_qysbs

	this.Layout = "index.html"
	this.TplName = "cert_qysb_list.html"
}

func (this *AppController)  Query_cert_wxd(){

	cert_wxd  := []models.Cert_wxd{}
	cert_wxd = models.ListCert_wxd()

	this.Data["datas"] = cert_wxd

	this.Layout = "index.html"
	this.TplName = "cert_wxd_list.html"
}

func (this *AppController)  Query_cert_cpdj(){
	cert_cpdjs  := []models.Cert_cpdj{}
	cert_cpdjs = models.ListCert_cpdj()

	this.Data["datas"] = cert_cpdjs

	this.Layout = "index.html"
	this.TplName = "cert_cpdj_list.html"
}

func (this *AppController)  AddPace(){
	model := this.GetString("model")
	id ,_:= this.GetInt("id")
	pace,_ := this.GetInt("pace")
	beego.Info(model + string(id) + string(pace))
	if(pace != 4){
		pace = pace + 1
	}
	if(model == "wxd"){
		cert_wxd :=  models.Cert_wxd{Id:id,Pace:pace}
		models.UpdateCert_wxd(cert_wxd)
	}else if(model == "cpdj"){
		cert_cpdj :=  models.Cert_cpdj{Id:id,Pace:pace}
		models.UpdateCert_cpdj(cert_cpdj)
	}else if(model == "qysb"){
		cert_qysb :=  models.Cert_qysb{Id:id,Pace:pace}
		models.UpdateCert_qysb(cert_qysb)
	}
}